import { User, FanClub } from './sequelize';

export interface UserData {
  id: string;
  name: string;
  displayId?: string;
  shortId?: string;
  gender?: number;
}

export class UserService {
  
  // 保存/更新用户信息
  async upsertUser(userData: UserData) {
    return await User.upsert({
      id: userData.id,
      name: userData.name,
      displayId: userData.displayId,
      shortId: userData.shortId,
      gender: userData.gender
    });
  }

  // 获取用户信息
  async getUser(userId: string) {
    return await User.findByPk(userId, {
      include: [{ model: FanClub, as: 'fanClubs' }]
    });
  }

  // 保存粉丝团关系
  async upsertFanClub(userId: string, roomId: string, level: number, name?: string) {
    return await FanClub.upsert({
      userId,
      roomId,
      level,
      name
    });
  }
}
